/**
 * 订单管理 交易订单
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>交易订单</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <!-- <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.machineNo" placeholder="输入终端编号"></el-input>
      </el-form-item> -->
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.order_num" placeholder="输入订单号"></el-input>
      </el-form-item>
      <!-- <el-form-item>
        <el-input size="small" v-model="formInline.transId" placeholder="输入交易单号"></el-input>
      </el-form-item> -->
      <!-- <el-form-item>
        <el-select size="small" v-model="formInline.payType" placeholder="请选择">
          <el-option v-for="type in payType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.orderStatus" placeholder="请选择">
          <el-option v-for="type in payway" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="index" width="60">
      </el-table-column>
        <el-table-column sortable prop="hotelname" label="酒店名称" width="180" show-overflow-tooltip align="center">
      </el-table-column> 
      <el-table-column sortable prop="order_num" label="订单号" width="120" show-overflow-tooltip align="center">
      </el-table-column>    
       <el-table-column sortable prop="type" label="房型" width="120" show-overflow-tooltip align="center">
      </el-table-column >  
       <el-table-column sortable prop="oname" label="姓名" width="120" show-overflow-tooltip align="center">
      </el-table-column > 
      <el-table-column sortable prop="price" label="支付金额" width="120" show-overflow-tooltip align="center">
        <template slot-scope="scope">￥{{scope.row.price}}</template> 
      </el-table-column>
      <el-table-column sortable prop="remark" label="标记" width="100" show-overflow-tooltip align="center">
      </el-table-column>
      <el-table-column sortable prop="checkin" label="入住时间" width="120" show-overflow-tooltip align="center">
      </el-table-column>
      <el-table-column sortable prop="checkout" label="退房时间" width="120" show-overflow-tooltip align="center">
      </el-table-column>    

      
      <el-table-column align="center" label="操作" min-width="120">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">预览</el-button>
          <el-button size="mini" type="danger" @click="delOrder(scope.$index,scope.row)">退款</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 编辑界面 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click="closeDialog('editForm')">
      <el-form label-width="120px" :model="editForm" ref="editForm">
        <el-row>
          <el-col :span="12">     
            <el-form-item label="订单号">
              <el-input size="small" v-model="editForm.order_num" auto-complete="off" placeholder="请输入订单号" disabled></el-input>
            </el-form-item>
            <el-form-item label="支付金额">
              <el-input size="small" v-model="editForm.price" auto-complete="off" placeholder="请输入支付金额" disabled></el-input>
            </el-form-item>
            <el-form-item label="房间编号">
              <el-input size="small" v-model="editForm.room_id" auto-complete="off" placeholder="请输入房间编号" disabled>              
              </el-input>
            </el-form-item>
             <el-form-item label="姓名">
              <el-input size="small" v-model="editForm.oname" auto-complete="off" placeholder="请输入用户名" disabled></el-input>
            </el-form-item>
            <el-form-item label="电话号码">
              <el-input size="small" v-model="editForm.ophone" auto-complete="off" placeholder="请输入电话号码" disabled></el-input>
            </el-form-item>
          
          </el-col>  
          
         
        </el-row>
        
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {orderList,searchOrder,deleteOrder} from '@/api/Order'
import Pagination from '@/components/backstage/Pagination'

export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '预览', 
    
      editForm: {
        order_num: '',
        price: '',
        oname:'',
        checkin:'',
        type:'',
        hotelname:''
        // checkout

       
      },
      formInline: {
        page: 1,
        limit: 10,       
        order_num: ''
      },    
      
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      },
     paging:{
        page_Num:'',
        page_size:'',
        total:''
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取公司列表
    getdata(parameter) {
      this.loading = true
      orderList(parameter)
        .then(res => {
          // console.log(`order`,res);
          this.loading = false
          if (res.code == 0) {
            this.$message({
              type: 'info',
              message: res.msg
            })
          } else {
            this.listData = res.data
            // 分页赋值
            this.paging=res.paging;
            this.pageparm.currentPage = this.paging.page_Num
            this.pageparm.pageSize =  this.paging.page_size
            this.pageparm.total = this.paging.total
          }
        })
        .catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      // this.formInline.page = parm.currentPage
      // this.formInline.limit = parm.pageSize
      // this.getdata(this.formInline)
      this.$axios.get(`/ordering/list?page_num=${parm.currentPage}&page_size=${parm.pageSize}`).then(result=>{
        // console.log(result.data);
        this.loading = false
        this.listData = result.data.data;
        this.pageparm.currentPage = parm.currentPage
        this.pageparm.pageSize = parm.pageSize
    })},
    
    // 搜索事件
    search() {
      searchOrder(this.formInline.order_num).then(res=>{  
        console.log(res);
        this.loading = false
        this.listData = res.data;
        this.pageparm.currentPage = 1
        this.pageparm.pageSize = 10
        this.pageparm.total = 1
      })
    },
    //显示编辑界面
    handleEdit: function(index, row) {
      this.editFormVisible = true
      this.editForm = row
    },    
    // 删除订单
    delOrder(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // console.log('确定',row.oid);
          deleteOrder(row.oid)
          // this.$axios.delete(`/ordering/del/${row.oid}`)
          // OrderDelete(row.oid)
            .then(res => {
              // console.log(`order`,row.oid);
              if (res.code) {
                this.$message({
                  type: 'success',
                  message: '订单已删除!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('信息删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog(formName) {
      this.editFormVisible = false
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 

 